package com.wzy.oa_sys.controller.attendance;


import com.wzy.oa_sys.model.request.attendance.VacationReq;
import com.wzy.oa_sys.model.response.attendance.VacationResp;
import com.wzy.oa_sys.model.response.notice.NoticeResp;
import com.wzy.oa_sys.service.attendance.VacationService;
import com.wzy.oa_sys.service.notice.NoticeService;
import com.wzy.oa_sys.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 请假管理
 */
@RestController
@RequestMapping("/vacation")
public class VacationController {

    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private VacationService vacationService;

    @GetMapping("/list")
    public List<VacationResp> getVacationList() {
        return vacationService.getVacationList();
    }

    @GetMapping("/getApproved")
    public List<VacationResp> getApprovedVacationList(HttpServletRequest request) {
        return vacationService.getApprovedVacationList(request);
    }

    @PostMapping("/addVacation")
    public void addVacation(@RequestBody VacationReq vacationReq, HttpServletRequest request) {
        long userId = jwtUtil.extractUserId(request);
        System.out.println("新增请假："+vacationReq.toString());
        vacationService.addVacation(vacationReq,userId);
    }

    @DeleteMapping("/deleteVacationById/{id}")
    public void deleteVacationById(@PathVariable("id") Integer id) {
        System.out.println("删除请假："+id);
        int i = vacationService.deleteVacationById(id);
        System.out.println("删除结果："+i);
    }

    @GetMapping("/getVacationDetailById/{id}")
    public VacationResp getVacationDetailById(@PathVariable("id") Integer id) {
        return vacationService.getVacationDetailById(id);
    }

    @GetMapping("/getICanApprovedVacations")
    public List<VacationResp> getICanApprovedVacations(HttpServletRequest request) {
        long userId = jwtUtil.extractUserId(request);
        System.out.println("=====当前用户id："+userId);
        return vacationService.getICanApprovedVacations(userId);
    }

    @PostMapping("/updateTheVacation")
    public void updateTheVacation(@RequestBody VacationReq vacationReq, HttpServletRequest request) {
        System.out.println("更新的请假信息："+vacationReq.toString());
        vacationService.updateTheVacation(vacationReq,request);
    }
    //查看我可查看的请假信息
    //管理员查看所有，普通管理员查看本部门，普通用户查看自己
    @GetMapping("/getICanSeeVacations")
    public List<VacationResp> getICanSeeVacations(HttpServletRequest request) {
        return vacationService.getICanSeeVacations(request);
    }

    @PostMapping("/updateVacation")
    public void updateVacation(@RequestBody VacationReq vacationReq, HttpServletRequest request) {
        System.out.println("更新的请假信息："+vacationReq.toString());
        vacationService.updateVacation(vacationReq,request);
    }


}
